<template>
	<w-layout showNavbar navTitle="口令记录" :navTitleColor="publicStyles['--color-t1']" background="url('/static/image/bk.png') no-repeat"
		navBackgroundColor="transparent" :scrollTop="page.scrollTop" :navScrollColor="publicStyles['--color-bk']">
		<template #default>
			<view class="container">
				<up-tabs
					@change="tabChange"
					:list="tabs.list" 
					:current="tabs.current"
					lineWidth="14"
					lineHeight="14"
					:lineColor="`url('/static/icon/public/top-fill.png') 100% 100%`"
					:activeStyle="{
						color: publicStyles['--color'],
						fontWeight: 'bold',
						transform: 'scale(1.2)'
					}"
					:scrollable="false"
					itemStyle="height: 60px;"
				>
				</up-tabs>
				<view class="">
					<view @click="$u.route(`/pages/red_envelope/detail?id=${item.id}`)" class="public-card-2 px-50 py-50 mt-40" v-for="(item,index) in state.list" :key="index">
						<view class="fr-ac-jsb">
							<view class="fs-32">
								{{item.total_money}}精粹红包
							</view>
							<view class="op-70">
								{{item.addtime}}
							</view>
						</view>
						<view class="fr-ac-jsb mt-30">
							<view class="">
								已领取<text class="color">{{item.receive_num}}/{{item.num}}</text>个，共<text class="color">{{item.get_money}}</text>精粹
							</view>
							<view class="fr-ac">
								<view class="mr-5 color">
									领取详情
								</view>
								<image style="width: 26rpx;height: 26rpx;" src="/static/icon/public/right-fill.png" mode="widthFix"></image>
							</view>
						</view>
					</view>
				</view>
				<no-more :show="state.list.length == 0"></no-more>
			</view>
		</template>
	</w-layout>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted,
		computed,
		nextTick
	} from 'vue'
	import {
		storeToRefs
	} from 'pinia'
	import {
		onLoad, onPageScroll,
		onReachBottom,
		onShow
	} from '@dcloudio/uni-app'
	import {
		useAppStore
	} from '@/store/app'
	import {
		useColorStore
	} from '@/store/color'
	import {
		red_envelope_list
	} from '@/utils/request/api';
	import {
		useUserStore
	} from '@/store/user'
	const userStore = useUserStore()
	const appStore = useAppStore()
	const colorStore = useColorStore()
	const {
		publicStyles
	} = storeToRefs(colorStore)
	onLoad(async(options) => {
	})
	onShow(async(options) => {
		initData()
		get_red_envelope_list()
	})
	onMounted(() => {
		appStore.loadingHandler(false)
	})
	onPageScroll((e)=>{
		page.scrollTop = e.scrollTop
	})
	onReachBottom(()=>{
		if(state.last_limit == state.limit){
			state.page++
			get_red_envelope_list()
		}
	})
	const page = reactive({
		scrollTop:0
	})
	
	const tabs = reactive({
		current:0,
		list:[
			{
				id:1,
				name:'进行中',
			},
			{
				id:3,
				name:'已结束',
			},
			{
				id:2,
				name:'已参与',
			}
		]
	})
	function tabChange(e){
		tabs.current = e.index
		console.log(tabs.current)
		initData()
		get_red_envelope_list()
	}
	
	const state = reactive({
		list:[],
		page:1,
		limit:15,
		last_limit:15,
	})
	function initData(){
		state.list = []
		state.page = 1
		state.last_limit = 15
	}
	async function get_red_envelope_list(){
		const res = await red_envelope_list({
			page: state.page,
			type: tabs.list[tabs.current].id
		})
		state.last_limit = res.record.list.length
		state.list = state.list.concat(res.record.list)
	}
</script>

<style lang="scss">
	.shadow {
		box-shadow: 2rpx 2rpx 12rpx var(--shadow);
	}
	.color{
		color: var(--color);
	}

	.container {
		width: 100%;
		min-height: 100%;
		position: relative;
		overflow: hidden;
		box-sizing: border-box;
		padding: 0 30rpx;
		
	}
</style>